<template>
  <div class="tuandui">
      <group v-for="(item, index) in teamList" :key="index">
        <group-title slot="title">{{item.department}}<span style="float:right; color:#0078de">查看全部</span></group-title>
        <cell :title="li.name" v-if="item.department === li.department" v-for="(li,key) in list" :key="key">
          <span slot="icon" class="bgimg" v-show="!li.head_img">{{li.bgName}}</span>
          <img v-show="li.head_img" class="img" width="40" height="40" slot="icon" v-lazy="li.head_img"/>
          <span class="working" v-show="li.status === 1">工作中</span>
          <span class="working leave" v-show="li.status === 0">已离开</span>
        </cell>
      </group>
      <back-top></back-top>
  </div>
</template>

<script>
import {Cell, Group, GroupTitle} from 'vux'
import {getTeamList} from '../../api/supervisor'
import backTop from '../common/backTop'
export default {
  data () {
    return {
      teamList: [],
      list: [],
      status: ''
      // showBackTop: false
    }
  },
  components: {
    Cell,
    Group,
    GroupTitle,
    backTop
  },
  created () {
    this._getTeamList()
  },
  // mounted () {
  //   window.addEventListener('scroll', this._handleScroll)
  // },
  methods: {
    _getTeamList () {
      var list = []
      getTeamList().then(res => {
        if (res.code === 200) {
          this.teamList = res.data.data
          this.status = res.data.status
          this.teamList.forEach((item, index) => {
            for (var key in item) {
              if (!isNaN(parseInt(key))) {
                list.push(item[key])
              }
            }
          })
          this.list = list
          this.list.forEach(list => {
            this.$set(list, 'bgName', list.name.substring(list.name.length - 2))
          })
        } else if (res.code === 400) {
          this.noTeam = res.code
        }
      })
    }
  }
}
</script>

<style lang="scss">
.tuandui {
  margin-top: 44px;
  .weui-cells__title{
    margin: 0;
    padding: 10px;
    background-color: #f2f2f2;
    color: #666;
  }
  .bgimg{
    display: inline-block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    line-height: 40px;
    text-align: center;
    background-color: #0078de;
    color: #fff;
    font-size: 15px;
    margin-right: 5px;
  }
  .img{
    border-radius: 50%;
    margin-right: 5px;
  }
  .working{
    width: 40px;
    height: 40px;
    line-height: 40px;
    display: inline-block;
    text-align: center;
    background-color: #0078de;
    color: white;
    font-size: 10px;
    border-radius: 50%;
  }
  .leave{
    background-color: #ccc;
  }
}
</style>
